package com.example.wendao.view.ui.fragment;


import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.databinding.DataBindingUtil;
import androidx.fragment.app.Fragment;
import androidx.lifecycle.LiveData;
import androidx.paging.PagedList;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.example.wendao.R;
import com.example.wendao.databinding.FragmentMallBinding;
import com.example.wendao.model.entity.Goods;
import com.example.wendao.model.service.GoodsService;
import com.example.wendao.view.adapter.MallAdapter;
import com.example.wendao.view.adapter.MallListAdapter;
import com.example.wendao.viewmodel.GoodsViewModel;

import java.util.ArrayList;
import java.util.List;


/**
 * A simple {@link Fragment} subclass.
 */
public class MallFragment extends Fragment {
    private MallListAdapter adapter = new MallListAdapter();
    private GoodsViewModel goodsViewModel = null;
    private RecyclerView recyclerView;
    private LiveData<PagedList<Goods>> goods;
    private GoodsService goodsService;
    private FragmentMallBinding fragmentMallBinding;
    private List<Goods> goodsList = new ArrayList<>();

    public MallFragment() {}


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        fragmentMallBinding= DataBindingUtil.inflate(inflater,R.layout.fragment_mall,container,false);
        View view=fragmentMallBinding.getRoot();
        recyclerView=view.findViewById(R.id.rv_mall);
        initFruits();
        LinearLayoutManager layoutManager = new LinearLayoutManager(view.getContext());
        recyclerView.setLayoutManager(layoutManager);
        MallAdapter adapter=new MallAdapter(goodsList);
        recyclerView.setAdapter(adapter);
        return view;
    }

    private void initFruits() {
        for (int i = 0; i < 2; i++) {
            /*  this.goodId = goodId;
                this.goodName = goodName;
                this.goodPrice = goodPrice;
                this.goodInfo = goodInfo;
                this.goodPic = goodPic;*/
            Goods apple = new Goods(1,"Apple",33,"好吃",null );
            goodsList.add(apple);
            Goods banana = new Goods(2,"Banana", 33,"好吃",null);
            goodsList.add(banana);
            Goods orange = new Goods(3,"orange",99,"好吃",null);
            goodsList.add(orange);
        }
    }
}
